﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using YFIN.Admin.AdminServiceRef;
using YFIN.Admin.ViewModels;

namespace YFIN.Admin.Admin
{
    public partial class AdminView : UserControl
    {
        public AdminView()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MainPage.TheMainPage.LayoutRoot.Children[0] = new AdminLogin();
            MainPage.Admin = null;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var m = new AdminPwdUpdate();
            m.Show();
            m.Closed +=
                (msender, me) =>
                {
                    if (m.DialogResult.HasValue && m.DialogResult.Value)
                    {
                        var client = new AdminServiceClient();
                        client.UpdateCompleted += new EventHandler<UpdateCompletedEventArgs>(client_UpdateCompleted);
                        client.UpdateAsync(MainPage.Admin);
                    }
                };
        }

        private void client_UpdateCompleted(object sender, UpdateCompletedEventArgs e)
        {
            if(e.Result)
            {
                MessageBox.Show("修改成功！");
            }
        }
    }
}
